home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / MFC_Samples / ctrltest / spintest.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  2.7 KB  |  112 lines

  1. // spintest.cpp : New control example - Uses MicroScroll32
  2. //                custom control DLL from MuScrl32 sample
  3. //
  4. // This is a part of the Microsoft Foundation Classes C++ library.
  5. // Copyright (C) 1999 Microsoft Corporation
  6. // All rights reserved.
  7. //
  8. // This source code is only intended as a supplement to the
  9. // Microsoft Foundation Classes Reference and related
  10. // electronic documentation provided with the library.
  11. // See these sources for detailed information regarding the
  12. // Microsoft Foundation Classes product.
  13.  
  14. #include "stdafx.h"
  15. #include "ctrltest.h"
  16.  
  17. #include "paredit.h"
  18.  
  19. /////////////////////////////////////////////////////////////////////////////
  20. // Example of a dialog with special controls in it
  21.  
  22. #define NUM_EDIT        4
  23. #define IDC_EDIT_MIN    IDC_EDIT1
  24. #define IDC_BUTTON_MAX  IDC_BUTTON4
  25.     // IDC_EDIT1->IDC_EDIT4 and IDC_BUTTON1->IDC_BUTTON4 must be contiguous
  26.  
  27. class CSpinEditDlg : public CDialog
  28. {
  29. protected:
  30.     CParsedEdit edit[NUM_EDIT];
  31. public:
  32.     //{{AFX_DATA(CSpinEditDlg)
  33.         enum { IDD = IDD_SPIN_EDIT };
  34.     //}}AFX_DATA
  35.     CSpinEditDlg()
  36.         : CDialog(CSpinEditDlg::IDD)
  37.             { }
  38.  
  39.     BOOL OnInitDialog();
  40.     //{{AFX_MSG(CSpinEditDlg)
  41.         virtual void OnOK();
  42.     //}}AFX_MSG
  43.     DECLARE_MESSAGE_MAP()
  44. };
  45.  
  46. BEGIN_MESSAGE_MAP(CSpinEditDlg, CDialog)
  47.     //{{AFX_MSG_MAP(CSpinEditDlg)
  48.     //}}AFX_MSG_MAP
  49. END_MESSAGE_MAP()
  50.  
  51.  
  52. BOOL CSpinEditDlg::OnInitDialog()
  53. {
  54.     int value = 1;
  55.     for (int i = 0; i < NUM_EDIT; i++)
  56.     {
  57.         // associate button with edit item
  58.         CSpinButtonCtrl* pSpin = (CSpinButtonCtrl*)GetDlgItem(IDC_BUTTON_MAX - i);
  59.         ASSERT(pSpin != NULL);
  60.         pSpin->SetPos(value++);        // 1, 2, 3, 4
  61.         pSpin->SetRange(0,100);
  62.     }
  63.     return TRUE;
  64. }
  65.  
  66. void CSpinEditDlg::OnOK()
  67. {
  68.     int values[NUM_EDIT];
  69.     UINT nID = 0;
  70.     BOOL bOk = TRUE;
  71.     for (int i = 0; bOk && i < NUM_EDIT; i++)
  72.     {
  73.         nID = IDC_EDIT_MIN + i;
  74.         values[i] = ::GetDlgItemInt(m_hWnd, nID, &bOk, TRUE);
  75.         if (values[i] < 0 || values[i] > 100)
  76.             bOk = FALSE;
  77.     }
  78.  
  79.     if (!bOk)
  80.     {
  81.         // report illegal value
  82.         CString str;
  83.         str.LoadString(IDS_ILLEGAL_VALUE);
  84.         MessageBox(str);
  85.         CEdit& badEdit = *(CEdit*)GetDlgItem(nID);
  86.         badEdit.SetSel(0, -1);
  87.         badEdit.SetFocus();
  88.         return;     // don't end dialog
  89.     }
  90.  
  91. #ifdef _DEBUG
  92.     // dump results, normally you would do something with these
  93.     TRACE0("Final values:\n");
  94.     for (i = 0; i < NUM_EDIT; i++)
  95.         TRACE1("\t%d\n", values[i]);
  96. #endif
  97.     EndDialog(IDOK);
  98. }
  99.  
  100. /////////////////////////////////////////////////////////////////////////////
  101. // Run the test
  102.  
  103. void CTestWindow::OnTestSpinEdit()
  104. {
  105.     TRACE0("running dialog with spin controls in it\n");
  106.     CSpinEditDlg dlg;
  107.     dlg.DoModal();
  108. }
  109.  
  110.  
  111. /////////////////////////////////////////////////////////////////////////////
  112.